<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">全部用户</block>
		</cu-custom>
		<view class="cu-list menu-avatar">
			<view class="cu-item" v-for="(item,index) in list" :key="index" @tap="onDetail(item.id)">
				<view class="cu-avatar round lg" :style="'background-image:url(' + item.avatarUrl + ')'">
				</view>
				<view class="content">
					<view class="text-black">{{item.nickName}}</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							{{item.phone}}
						</view>
					</view>
					<view class='cu-tag radius sm' :class="item.userGrade == '1' ?'line-red' :'line-blue'">
						{{item.userGrade == '1' ?'会员用户' :'普通用户'}}
					</view>
				</view>
				<view class="action">
					<view class="text-black">来源</view>
					<view class="text-grey text-xs">
						{{item.userSource == 'WX-MA' ?'微信小程序' : item.userSource == 'ALI-MA' ? '支付宝小程序' : item.userSource == 'H5' ? '普通H5' : item.userSource == 'APP' ? 'APP' :'未知'}}
					</view>
				</view>
			</view>
		</view>
		<view class="cu-load bg-gray" :class="isLoad?'loading':'over'">
		</view>
	</view>
</template>


<script>
	import {
		getPage
	} from '@/api/mall/userinfo.js'
	export default {
		data() {
			return {
				queryParams: {},
				page: {
					total: 0,
					currentPage: 1,
					pageSize: 10,
					descs: 'create_time',
				},
				list: [],
				isLoad: true
			}
		},
		onShow() {
			this.refreshPage()
		},
		onReachBottom() {
			if (this.isLoad) {
				this.page.currentPage = this.page.currentPage + 1;
				this.initPage();
			}
		},
		onPullDownRefresh() {
			// 在当前页面显示导航条加载动画。
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: '#ff0000',
				animation: {
					duration: 400,
					timingFunc: 'easeIn'
				}
			})
			this.refreshPage();
			uni.hideNavigationBarLoading(); // 在当前页面隐藏导航条加载动画。
			uni.stopPullDownRefresh();
		},

		methods: {
			initPage() {
				let params = {
					current: this.page.currentPage,
					size: this.page.pageSize,
					descs: this.page.descs,
				}
				getPage(Object.assign(params, this.queryParams)).then(res => {
					let userInfoList = res.data.records;
					this.list = [...this.list, ...userInfoList];
					if (userInfoList.length < this.page.pageSize) {
						this.isLoad = false;
					}
				})
			},
			refreshPage() {
				this.isLoad = true;
				this.list = [];
				this.page.currentPage = 1;
				this.initPage();
			},
			onDetail(id) {
				uni.navigateTo({
					url: "/pages/mall/userinfo/user-detail/index?id=" + id
				})
			}
		}
	}
</script>


<style>
</style>
